Skip to content

Conversation

@petrCher
Copy link
Member

@petrCher petrCher commented Aug 4, 2025

Задание: #134

Изменения

Исправил ошибку с удалением своего комментария. Раньше не имея скоупов админа нельзя было удалить свой комментарий, теперь можно.

Детали реализации

Все протестил при разных случаях, теперь работает. Раньше выбрасывало ошибку 500 из-за ошибки в коде эндпоинта. в структуре Comment нет is_anonymous, поэтому правильная реализация это: comment.user_id == None
Именно из-за этого все падало. А при админских правах ошибки не возникало, так как до этой части кода просто не доходило дело, она используется только обычными пользователями.

Check-List

  • Вы проверили свой код перед отправкой запроса?
  • Вы написали тесты к реализованным функциям?
  • Вы не забыли применить форматирование black и isort для Back-End или Prettier для Front-End?

@github-actions
Copy link

github-actions bot commented Aug 4, 2025

Code Coverage

Coverage Report
FileStmtsMissCoverMissing
rating_api
   __main__.py440%1–7
   exceptions.py43784%35–37, 48–50, 58
rating_api/models
   base.py64494%24–27
   db.py126596%76, 90, 99, 152, 170
rating_api/routes
   base.py16194%41
   comment.py1233175%64, 82, 123–125, 146–155, 220–221, 223–224, 232–237, 264, 277, 304–315, 346
   exc_handlers.py32391%36, 43, 50
   lecturer.py891682%136, 141–167, 183, 191, 209, 215
rating_api/schemas
   base.py12467%6–9
   models.py144398%108–110
TOTAL6957889% 

Summary

Tests Skipped Failures Errors Time
52 0 💤 0 ❌ 0 🔥 11.909s ⏱️

@petrCher petrCher requested a review from Zimovchik August 4, 2025 21:09
if not has_delete_scope:
if comment.user_id == None:
raise ForbiddenAction(Comment)
elif str(comment.user_id) != str(user.get('id')):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем str

Comment on lines 312 to 315
if comment.user_id == None:
raise ForbiddenAction(Comment)
elif str(comment.user_id) != str(user.get('id')):
raise ForbiddenAction(Comment)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно в одно выражение через or

@petrCher
Copy link
Member Author

petrCher commented Aug 5, 2025

@Zimovchik все еще раз протестил после изменений, работает

@Zimovchik Zimovchik merged commit 40af59b into main Aug 5, 2025
2 checks passed
@petrCher petrCher deleted the bad_delete_comment branch August 14, 2025 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] /comment/{uuid} DELETE комментарий не удаляется

3 participants